package pers.wensheng.patterns.behavioral_pattern.iterator_pattern.my_impl;

import pers.wensheng.patterns.behavioral_pattern.iterator_pattern.my_impl.entity.StudentAggregateImpl;
import pers.wensheng.patterns.behavioral_pattern.iterator_pattern.my_impl.entity.StudentIterator;

/**
 * 迭代器模式
 * 当我们在使用JAVA开发的时候，想使用迭代器模式的话，
 * 只要让我们自己定义的容器类实现 java.util.Iterable 并实现其中的iterator()方法
 * 使其返回一个  java.util.Iterator  的实现类就可以了。
 */
public class Client {
    public static void main(String[] args) {
        StudentAggregateImpl aggregate = new StudentAggregateImpl();
        aggregate.addStudent(new Student("sun","001"));
        aggregate.addStudent(new Student("wen","002"));
        aggregate.addStudent(new Student("sheng","003"));
        aggregate.addStudent(new Student("hao","004"));

        StudentIterator iterator = aggregate.getStudentIterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

    }
}
